<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>添加管理员</title>
    <meta name="keywords" content="*Sway*--后台管理系统">
    <meta name="description" content="*Sway*--后台管理系统">

    <link rel="shortcut icon" href="/favicon.ico">
    <link href="/Public/Admin/css/bootstrap.min14ed.css" rel="stylesheet">
    <link href="/Public/Admin/css/font-awesome.min93e3.css" rel="stylesheet">
    <link href="/Public/Admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <!-- Gritter -->
    <link href="/Public/Admin/js/plugins/gritter/jquery.gritter.css" rel="stylesheet">
    <!-- Morris -->
    <link href="/Public/Admin/css/plugins/morris/morris-0.4.3.min.css" rel="stylesheet">
    <link href="/Public/Admin/css/animate.min.css" rel="stylesheet">
    <link href="/Public/Admin/css/style.min862f.css" rel="stylesheet">
    <link href="/Public/Admin/css/plugins/switchery/switchery.css" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加管理员</h5>
                </div>
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <div class="col-md-2">
                            <a href="<?php echo U('Admin/admin/index');?>" class="btn btn-outline btn-primary">返回管理员列表</a>
                        </div>
                    </div>
                    <form class="form-horizontal m-t" id="addForm" enctype="multipart/form-data" action="<?php echo U('Admin/admin/Save');?>">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">用户名:</label>
                            <div class="col-sm-8">
                                <input id="name" name="name" class="form-control" type="text">
                                <span class="help-block m-b-none"></span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">用户组:</label>
                            <div class="col-sm-8">
                                <select class="form-control m-b" name="groupid">
                                    <option value="">-----请为管理员选择所属用户组-----</option>
                                    <?php if(is_array($groupInfo)): $i = 0; $__LIST__ = $groupInfo;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$v): $mod = ($i % 2 );++$i;?><option value="<?php echo ($v["id"]); ?>"><?php echo ($v["title"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">密码:</label>
                            <div class="col-sm-8">
                                <input id="pwd" name="pwd" class="form-control" type="password">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">确认密码:</label>
                            <div class="col-sm-8">
                                <input id="confirm_pwd" name="confirm_pwd" class="form-control" type="password">
                                <span class="help-block m-b-none"></span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">真实姓名:</label>
                            <div class="col-sm-8">
                                <input id="realName" name="realName" class="form-control" type="text" aria-required="true" aria-invalid="false" class="valid">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">上传头像:</label>
                            <div class="col-sm-8">
                                <input id="img" name="img" class="form-control" type="file" aria-required="true" aria-invalid="false" class="valid">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">状态:</label>
                            <div class="col-sm-8">
                                <input type="checkbox" class="js-switch form-control" value="1" name="status" id="status" checked/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/Public/Admin/js/jquery.min.js"></script>
<script src="/Public/Admin/js/bootstrap.min.js"></script>
<script src="/Public/Admin/js/plugins/layer.3/layer.js"></script>
<script src="/Public/Admin/js/common.js"></script>
<script src="/Public/Admin/js/content.min.js"></script>
<script src="/Public/Admin/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/Public/Admin/js/plugins/validate/messages_zh.min.js"></script>
<script src="/Public/Admin/js/plugins/switchery/switchery.js"></script>
<script>
    var elem = document.querySelector('.js-switch');
    var init = new Switchery(elem);

    $(function(){
        // 姓名格式验证
        jQuery.validator.addMethod("checkname", function(value, element) {
            if(/^[a-zA-Z0-9_-]{3,16}$/.test(value)) {
                return true;
            }else{
                return false;
            }
        }, "");
        $.validator.setDefaults({
            highlight: function (e) {
                $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
            }, success: function (e) {
                e.closest(".form-group").removeClass("has-error").addClass("has-success")
            }, errorElement: "span", errorPlacement: function (e, r) {
                e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
            }, errorClass: "help-block m-b-none", validClass: "help-block m-b-none"
        }), $().ready(function () {
            var e = "<i class='fa fa-times-circle'></i> ";

            $("#addForm").validate({
                rules: {
                    name: {required: true, minlength: 5, maxlength: 15, checkname: true},
                    pwd: {required: true, minlength: 5, maxlength: 15},
                    confirm_pwd: {required: true, minlength: 5, maxlength: 15, equalTo: "#pwd"},
                    realName: "required",
                    groupid: "required"
                },
                messages: {
                    name: {required: e + "请输入您的用户名", minlength: e + "用户名必须5个字符以上", maxlength: e + "用户名必须小于15个字符", checkname: e + "用户名必须为5-15位数字或字母"},
                    pwd: {required: e + "请输入您的密码", minlength: e + "密码必须5个字符以上", maxlength: e + "密码必须小于15个字符"},
                    confirm_pwd: {required: e + "请再次输入密码", minlength: e + "密码必须5个字符以上", maxlength: e + "密码必须小于15个字符", equalTo: e + "两次输入的密码不一致"},
                    realName: e + "请输入您的真实姓名",
                    groupid: e + "请为管理员选择所属用户组"
                },
                submitHandler: function(form){
                    //  获取表单的值  循环进data
//                    var objectArr = $(form).serializeArray();
//                    var data = new Object();
//                    $.each(objectArr,function(k,v){
//                        data[v.name] = v.value;
//                    });
//
//                    $.post(
//                        "<?php echo U('Admin/admin/Save');?>",
//                        data,
//                        function(data){
//                            if(data.status > 0){
//                                common.error(data.msg);
//                            }else{
//                                common.success(data.msg,"<?php echo U('Admin/admin/index');?>");
//                            }
//                        },
//                        'JSON'
//                    );

                    var data = new  FormData(document.getElementById('addForm'));
                    $.ajax({
                        url:$(form).attr('action'),
                        type:"POST",
                        data:data,
                        cache: false,
                        processData:false,
                        contentType:false,
                        success:function(data){
                            if(data.status > 0){
                                common.error(data.msg);
                            }else{
                                common.success(data.msg,"<?php echo U('Admin/admin/index');?>");
                            }
                        },
                        dataType:'JSON'
                    });
                }
            });
        });

    });
</script>
</body>
</html>